package cn.ccit.action;

import java.util.List;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ModelDriven;

import cn.ccit.base.BaseConstants;
import cn.ccit.entites.UserAuthority;
import cn.ccit.iservers.IUserAuthorityServers;
import cn.ccit.model.BaseModel;
import cn.ccit.servers.UserAuthorityServers;
import cn.ccit.util.GsonUtil;

public class UserAuthorityAction extends BaseAction implements ModelDriven<UserAuthority>{
	private IUserAuthorityServers iuas=new UserAuthorityServers();
	private UserAuthority ua=new UserAuthority();
	private String idList;
	public String addUserAuthority(){
		BaseModel<UserAuthority> uaModel =new BaseModel<UserAuthority>();
		if(iuas.addUserAuthority(ua)){
			uaModel.setStatus(BaseConstants.SUCESSFUL_STATE_CODE);
			uaModel.setMessage(BaseConstants.SUCESSFUL_STATE_MESSAGE);
		}else{
			uaModel.setStatus(BaseConstants.FAIL_STATE_CODE);
			uaModel.setMessage(BaseConstants.FAIL_STATE_MESSAGE);
		}
		GsonUtil.GsonString(uaModel);
		return Action.SUCCESS;
	}
	public String removeUserAuthority(){
		BaseModel<UserAuthority> uaModel =new BaseModel<UserAuthority>();
		if(iuas.removeUserAuthority(ua)){
			uaModel.setStatus(BaseConstants.SUCESSFUL_STATE_CODE);
			uaModel.setMessage(BaseConstants.SUCESSFUL_STATE_MESSAGE);
		}else{
			uaModel.setStatus(BaseConstants.FAIL_STATE_CODE);
			uaModel.setMessage(BaseConstants.FAIL_STATE_MESSAGE);
		}
		GsonUtil.GsonString(uaModel);
		return Action.SUCCESS;
	}
	public String changeUserAuthorityInfo(UserAuthority ua){
		BaseModel<UserAuthority> uaModel =new BaseModel<UserAuthority>();
		if(iuas.changeUserAuthorityInfo(ua)){
			uaModel.setStatus(BaseConstants.SUCESSFUL_STATE_CODE);
			uaModel.setMessage(BaseConstants.SUCESSFUL_STATE_MESSAGE);
		}else{
			uaModel.setStatus(BaseConstants.FAIL_STATE_CODE);
			uaModel.setMessage(BaseConstants.FAIL_STATE_MESSAGE);
		}
		GsonUtil.GsonString(uaModel);
		return Action.SUCCESS;
	}
	public String getSomeUserAuthoritys(){
		BaseModel<List<UserAuthority>> uaListModel=new BaseModel<List<UserAuthority>>();
		sendJsonDataList(iuas.getSomeUserAuthoritys(startId, limit), uaListModel);
		return Action.SUCCESS;
	}
	public String searchUserAuthorityByID(int id){
		BaseModel<UserAuthority> uaModel =new BaseModel<UserAuthority>();
		if(iuas.searchUserAuthorityByID(ua.getId())!=null){
			uaModel.setStatus(BaseConstants.SUCESSFUL_STATE_CODE);
			uaModel.setData(iuas.searchUserAuthorityByID(ua.getId()));
			uaModel.setMessage(BaseConstants.SUCESSFUL_STATE_MESSAGE);
		}else{
			uaModel.setStatus(BaseConstants.FAIL_STATE_CODE);
			uaModel.setMessage(BaseConstants.FAIL_STATE_MESSAGE);
		}
		GsonUtil.GsonString(uaModel);
		return Action.SUCCESS;
	}
	public String getUserAuthoritiesFromIdList(){
		BaseModel<List<UserAuthority>> uaListModel=new BaseModel<List<UserAuthority>>();
		if(iuas.getUserAuthoritiesFromIdList(idList)!=null){
			uaListModel.setStatus(BaseConstants.SUCESSFUL_STATE_CODE);
			uaListModel.setData(iuas.getUserAuthoritiesFromIdList(idList));
			uaListModel.setMessage(BaseConstants.SUCESSFUL_STATE_MESSAGE);
		}else{
			uaListModel.setStatus(BaseConstants.FAIL_STATE_CODE);
			uaListModel.setMessage(BaseConstants.FAIL_STATE_MESSAGE);
		}
		GsonUtil.GsonString(uaListModel);
		return Action.SUCCESS;
	}
	public String getIdList() {
		return idList;
	}
	public void setIdList(String idList) {
		this.idList = idList;
	}
	@Override
	public UserAuthority getModel() {
		return ua;
	}

}
